package me.greyliu.kuai.service;

import me.greyliu.kuai.dao.UserDao;
import me.greyliu.kuai.entity.Response;
import me.greyliu.kuai.entity.User;
import org.springframework.stereotype.Service;

@Service
public class UserService {
    UserDao userDao=new UserDao();
    public Response login(String name,String pwd){
        User user = userDao.getUserByName(name);
        if(user==null){
            return new Response(401,"用户名错误");
        }else if(user.getPwd().equals(EncodeService.encodePwd(pwd))){
            return new Response(202,"ok");
        }else{
            return new Response(402,"密码错误");
        }
    }
    public Response regist(String name,String pwd){
        User user = userDao.getUserByName(name);
        if(user==null) {
            userDao.InsertUser(name, EncodeService.encodePwd(pwd));
            return new Response(202,"注册成功");
        }else {
            return new Response(403,"用户已存在");
        }
    }
}
